---
title: Pyrefly Error Suppressions

description: Learn how to suppress type check errors in Pyrefly with code comments and baseline files.
---
import CodeSnippet from '@site/src/sandbox/CodeSnippet'

## Error Suppression Comments

The Python type system allows you to suppress errors with a comment. This feature can be helpful in many scenarios. For example, after enabling a type checker, suppressions can allow you to get a clean type check signal without having to stop and fix every pre-existing error in your code.

There are multiple ways to do this in Pyrefly.

```python
def foo() -> int:
  # pyrefly: ignore
  return "this is a type error"
```

You can also put the comment on the same line as the error.

```python
def foo() -> int:
  return "this is a type error" # pyrefly: ignore
```

You can also target specific error types:

```python
def foo() -> int:
  return "this is a type error" # pyrefly: ignore[bad-return]
```

We respect the specification and allow `type: ignore` to be used:

```python
def foo() -> int:
  return "this is a type error" # type: ignore
```


We also have a special comment that will ignore all errors in a file.


<pre>
  <CodeSnippet
  sampleFilename="why_hints.py"
  isCodeSnippet={true}
  codeSample={`# pyrefly: ignore-errors

from typing import *

def test(x: int):
    return f"{x}"

def bar() -> int:
    # this error won't be reported
    return ""
`}
  />
</pre>

Pyrefly can automatically suppress all type errors in your project if you run:

```
pyrefly check --suppress-errors
```

## Baseline Files (Experimental)

Pyrefly also supports storing errors in a baseline file. Any errors matching the baseline will be ignored and only new errors will be reported.
This is useful when introducing type checking to a project for the first time, or when rolling out changes that require many suppression comments.
This feature is inspired by tools like [basedpyright](https://docs.basedpyright.com/latest/benefits-over-pyright/baseline/) and [Android Studio](https://developer.android.com/studio/write/lint#snapshot).

To generate (or re-generate) the baseline file:

```
pyrefly check --baseline="<path to baseline file>" --update-baseline
```

To check your project using a baseline file and report only newly-introduced errors:

```
pyrefly check --baseline="<path to baseline file>"
```

Errors are matched with the baseline by looking at file, error code, and column number.
Right now, errors suppressed by the baseline file are still shown in the IDE and the baseline file can only be passed as a command line argument, but both are expected to change in the future.
This feature is experimental, so please submit any feedback or requests you have on our Github repo.

## Upgrading Pyrefly (And other changes that introduce new type errors)

Upgrading the version of Pyrefly you're using, or a third party library you depend on can surface new type errors in your code. Fixing them all at once is often not realistic. We've written scripts to help you temporarily silence them.

```
# step 1
pyrefly check --suppress-errors
```

```
# step 2
<run your formatter of choice>
```

```
# step 3
pyrefly check --remove-unused-ignores
```
Repeat the steps above until you get a clean formatting run and a clean type check.

This will add ` # pyrefly: ignore` comments to your code that will enable you to silence errors, and come back and fix them at a later date. This can make the process of upgrading a large codebase much more manageable.
